package org.dralee.springsecurity.controllers.api;

import org.dralee.springsecurity.models.ApiResult;
import org.dralee.springsecurity.models.LoginModel;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.awt.*;

/**
 * @author jackielee
 * @version 1.0
 * @description UserController
 * @date 2021/3/30
 **/
@RestController
@RequestMapping("/api")
public class UserLoginController {

    @PostMapping(value = "/login")
    public ApiResult login(@RequestBody LoginModel model){
        if(model.getUsername() == "admin" && model.getPassword() == "123456"){
            return ApiResult.success("admin login successfully");
        }
        if(model.getUsername() == "lee" && model.getPassword() == "123456"){
            return ApiResult.success("user login successfully");
        }
        return ApiResult.failure(403, "login failure, not a user.");
    }

    @RequestMapping(method = RequestMethod.GET,value = "/login2", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ApiResult login(@RequestParam("name") String name){
        return ApiResult.success("hello "+name);
    }
}
